package com.ryhx.pay.channel.app.paybank.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.ryhx.pay.channel.app.model.PayBank;
import com.ryhx.pay.channel.app.paybank.dao.PayBankDao;
import com.ryhx.pay.channel.app.paybank.service.PayBankService;
import com.ryhx.pay.common.exceptions.BizException;
import com.ryhx.pay.common.utils.BeanToMapUtils;

@Component("payBankService")
public class PayBankServiceImpl implements PayBankService {
	@Resource(name = "payBankDao")
	private PayBankDao payBankDao;

	@Override
	public PayBank getPayBank(Long entityId) throws BizException {
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("entityId", entityId);
		return payBankDao.getPayBank(query);
	}

	@Override
	public PayBank selectOnePayBankWillThrowException(Map<String, Object> query) throws BizException{
		return payBankDao.getPayBank(query);
	}

	@Override
	public PayBank selectFirstPayBank(Map<String, Object> query) throws BizException{
		query.put("limit", 1);
		List<PayBank> list = payBankDao.getPayBankList(query);
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<PayBank> getPayBankList(Map<String, Object> query) throws BizException {
		PayBank payBank = (PayBank) query.get("payBank");
		if (null != payBank) {
			Class<?> clazz = payBank.getClass();
			BeanToMapUtils.putBeanFiled(query, payBank, clazz);
		}
		return payBankDao.getPayBankList(query);
	}

	@Override
	public Integer getPayBankListCount(Map<String, Object> query) throws BizException {
		PayBank payBank = (PayBank) query.get("payBank");
		if (null != payBank) {
			Class<?> clazz = payBank.getClass();
			BeanToMapUtils.putBeanFiled(query, payBank, clazz);
		}
		return payBankDao.getPayBankListCount(query);
	}

	@Override
	public Long insertPayBank(PayBank payBank) throws BizException {
		return payBankDao.insertPayBank(payBank);
	}

	@Override
	public Long replacePayBank(PayBank payBank) throws BizException {
		return payBankDao.replacePayBank(payBank);
	}

	@Override
	public int updatePayBank(PayBank payBank) throws BizException {
		return payBankDao.updatePayBank(payBank);
	}

	@Override
	public int updatePayBankWithoutNull(PayBank payBank) throws BizException {
		return payBankDao.updatePayBankWithoutNull(payBank);
	}

	@Override
	public int updatePayBankByWhereSql(Map<String, Object> payBank, String whereSql) throws BizException {
		if (payBank == null || payBank.isEmpty()) {
			throw new RuntimeException("payBank不能为空");
		}
		if (StringUtils.isBlank(whereSql)) {
			throw new RuntimeException("whereSql不能为空");
		}
		payBank.put("whereSql", whereSql);
		return payBankDao.updatePayBankByWhereSql(payBank);
	}

	@Override
	public int deletePayBank(Long entityId) throws BizException {
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("entityId", entityId);
		return payBankDao.deletePayBank(query);
	}

	@Override
	public int deletePayBankList(Map<String, Object> payBank) throws BizException{
		return payBankDao.deletePayBankList(payBank);
	}

	@Override
	public int deletePayBankByWhereSql(String whereSql) throws BizException {
		if (StringUtils.isBlank(whereSql)) {
			throw new RuntimeException("whereSql不能为空");
		}
		Map<String, Object> query = new HashMap<String, Object>();
		query.put("whereSql", whereSql);
		return payBankDao.deletePayBankByWhereSql(query);
	}

	@Override
	public int truncatePayBank() throws BizException {
		return payBankDao.truncatePayBank();
	}

	@Override
	public int batchInsertPayBank(List<PayBank> payBankList) throws BizException {
		return payBankDao.batchInsertPayBank(payBankList);
	}

	@Override
	public int batchReplacePayBank(List<PayBank> payBankList) throws BizException {
		return payBankDao.batchReplacePayBank(payBankList);
	}

	@Override
	public int batchUpdatePayBank(List<PayBank> payBankList) throws BizException {
		return payBankDao.batchUpdatePayBank(payBankList);
	}

	@Override
	public int batchDeletePayBank(List<Long> idList) throws BizException {
		return payBankDao.batchDeletePayBank(idList);
	}

	@Override
	public int batchDeletePayBankList(List<PayBank> payBankList) throws BizException{
		return payBankDao.batchDeletePayBankList(payBankList);
	}
}
